alert('SceneProfile.js loaded');

var leftTmpSel;
var selS = 0;

function SceneProfile() {

};

SceneProfile.prototype.initialize = function () {
	alert("SceneProfile.initialize()");
	// this function will be called only once when the scene manager show this scene first time
	// initialize the scene controls and styles, and initialize your variables here
	// scene HTML and CSS will be loaded before this function is called
	
	selStats(selS);
	
	leftTmpSel = $('#selection').css('left');	
	leftTmpSel = parseInt(leftTmpSel.substring(0,leftTmpSel.lastIndexOf('p')));
	alert("-*-*-*-*-*-*-*-*-*-*-*-*-*");
	alert(selS + "/" + leftTmpSel);
	alert(0%4 + "/" + 1%4 + "/" + 2%4 + "/" + 3%4 + "/" + 4%4 + "/" + 5%4 + "/" + 6%4 + "/" + 7%4 + "/" + 8%4 + "/" + 9%4 + "/" + 10%4);
	alert("-*-*-*-*-*-*-*-*-*-*-*-*-*");

};

SceneProfile.prototype.handleShow = function (data) {
	alert("SceneProfile.handleShow()");
	// this function will be called when the scene manager show this scene
};

SceneProfile.prototype.handleHide = function () {
	alert("SceneProfile.handleHide()");
	selS = 0;
	selStats(selS);
	$('#selection').css('left','250px');
	leftTmpSel = $('#selection').css('left');	
	leftTmpSel = parseInt(leftTmpSel.substring(0,leftTmpSel.lastIndexOf('p')));
	alert("///////////////////////////////////////");
	alert(leftTmpSel + " / " + selS);
	alert("///////////////////////////////////////");
	// this function will be called when the scene manager hide this scene
};

SceneProfile.prototype.handleFocus = function () {
	alert("SceneProfile.handleFocus()");
	// this function will be called when the scene manager focus this scene
};

SceneProfile.prototype.handleBlur = function () {
	alert("SceneProfile.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
};

SceneProfile.prototype.handleKeyDown = function (keyCode) {
	alert("SceneProfile.handleKeyDown(" + keyCode + ")");
	// TODO : write an key event handler when this scene get focued
	switch (keyCode) {
		case sf.key.LEFT:
			selectionManager("-");
			alert(selS + "/" + leftTmpSel);
			break;
		case sf.key.RIGHT:
			selectionManager("+");
			alert(selS + "/" + leftTmpSel);
			break;
		case sf.key.UP:
			break;
		case sf.key.DOWN:
			break;
		case sf.key.ENTER:
			sf.scene.hide('Profile');
			sf.scene.show('Scene1');
			sf.scene.focus('Scene1');
			break;
		case sf.key.RETURN:
			event.preventDefault();
			sf.scene.hide('Profile');
			sf.scene.show('Menu');
			sf.scene.focus('Menu');
			break;
		default:
			alert("handle default key event, key code(" + keyCode + ")");
			break;
	}
};


function selStats(sel){
	switch (sel){
		case 0:
			$('#s1').css('visibility','visible');
			$('#s2').css('visibility','hidden');
			$('#s3').css('visibility','hidden');
			$('#s4').css('visibility','hidden');
			break;
		case 1:
			$('#s1').css('visibility','hidden');
			$('#s2').css('visibility','visible');
			$('#s3').css('visibility','hidden');
			$('#s4').css('visibility','hidden');
			break;
		case 2:
			$('#s1').css('visibility','hidden');
			$('#s2').css('visibility','hidden');
			$('#s3').css('visibility','visible');
			$('#s4').css('visibility','hidden');
			break;
		case 3:
			$('#s1').css('visibility','hidden');
			$('#s2').css('visibility','hidden');
			$('#s3').css('visibility','hidden');
			$('#s4').css('visibility','visible');
			break;
		default:
			alert("Wrong argument calling selStat function with sel = " + sel + ". the function await 0,1,2 or 3");			
	}	
}

function selectionManager(sign){
	switch (sign){
	
		case "+":
			
			//manage stats display
			selS = (selS+1)%4;
			
			//manage profile selection display
			alert("///////////////  "+leftTmpSel);
			if (leftTmpSel >= 850)
				$('#selection').css('left',(leftTmpSel -= 600) + "px");
			else
				$('#selection').css('left',(leftTmpSel+=200) + "px");
			
			break;
		
		case "-":
			
			//manage stats display
			if (selS == 0 )
				selS = 3;
			else
				selS = (selS-1)%4;
			
			//manage profile selection display
			alert("///////////////  "+leftTmpSel);
			if (leftTmpSel <= 251)
				$('#selection').css('left',(leftTmpSel += 600) + "px");
			else
				$('#selection').css('left',(leftTmpSel-=200) + "px");
			
			break;
	}
	selStats(selS);
	
}